package com.vne.skyemart.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.servlet.ModelAndView;

import com.vne.skyemart.model.ShippingType;
import com.vne.skyemart.service.ShippingTypeService;

@Controller
@SessionAttributes
@RequestMapping("/shippingType")
public class ShippingTypeController {

	@Autowired
	private ShippingTypeService shippingTypeService;

	@RequestMapping(value = "/save", method = RequestMethod.POST)
	public ModelAndView saveShippingType(@ModelAttribute(" shippingType") ShippingType shippingType,
			BindingResult result) {
		shippingTypeService.addShippingType(shippingType);
		return new ModelAndView("redirect:/shippingType.html");
	}

	@RequestMapping(method = RequestMethod.GET)
	public String listShippingType(Model model) {
		model.addAttribute("shippingType",  shippingTypeService.listShippingType());

		return "shippingTypeList";
	}

	@RequestMapping(value = "/add", method = RequestMethod.GET)
	public ModelAndView addShippingType(@ModelAttribute("shippingType") ShippingType shippingType,
			BindingResult result) {
		return new ModelAndView("addShippingType");
	}

}